package com.hgkj.cloud.customer.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.hgkj.cloud.base.domain.TenantConsult;
import com.hgkj.cloud.base.domain.TenantConsultDetail;
import com.hgkj.cloud.base.service.TenantConsultDetailService;
import com.hgkj.cloud.base.service.TenantConsultService;
import com.hgkj.cloud.customer.common.ResponseData;
import com.hgkj.cloud.base.domain.AdminUser;
import com.hgkj.cloud.base.service.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("consult")
public class AdminConsultController {

    @Autowired
    private TenantConsultService tenantConsultService;

    @Autowired
    private TenantConsultDetailService tenantConsultDetailService;

    @Autowired
    private AdminUserService adminUserService;

    /**
     *
     * @param pageNum
     * @param pageSize
     * @param user_uuid 登录用户id
     * @param toExamine 审核状态
     * @param title 查询条件
     * @return
     */
    //获取
    @RequestMapping("consultList")
    public ResponseData conList(Integer pageNum, Integer pageSize, String user_uuid, Integer toExamine, String title){
        ResponseData responseData = new ResponseData();
        Map map = new HashMap();
        map.put("uuid", user_uuid);
        AdminUser adminUser = adminUserService.getAdminUserByMap(map);
        Long framework_id = adminUser.getFramework_id();
        map.put("framework_id",framework_id);
        map.put("toExamine",toExamine);
        map.put("realName",title);
        Page<TenantConsultDetail> list = tenantConsultDetailService.getAllConsultDetail(pageNum,pageSize,map);
        PageInfo pageInfo = new PageInfo(list);
        map.clear();
        map.put("data",pageInfo);
        responseData.setData(map);
        return responseData;
    }

    //审核
    /**
     *
     * @param id 留言详情id
     * @param toExamine
     * @return
     */
    @RequestMapping("updateConsult")
    public ResponseData updateConsult(Long id,Integer toExamine){
        ResponseData responseData = new ResponseData();
        TenantConsultDetail tenantConsultDetail = tenantConsultDetailService.selectByPrimaryKey(id);
        tenantConsultDetail.setToExamine(toExamine);
        tenantConsultDetailService.updateByPrimaryKeySelective(tenantConsultDetail);
        if (tenantConsultDetail.getIsQuestion()== 1){//这是个问题
            TenantConsult tenantConsult =  new TenantConsult();
            tenantConsult.setId(tenantConsultDetail.getConsultId());
            tenantConsult.setToExamine(toExamine);
            tenantConsultService.updateByPrimaryKeySelective(tenantConsult);
        }
        return responseData;
    }

}
